<template>
	<view class="order-detail">
		<template v-if="detail">
		<template v-if="jxsFlag==='jxs'">
			<view class="order-address">
				<view class="icon-wrap"><i class="iconfont icondizhi1"></i></view>
				<view class="address-text">
					<view class="address">{{detail.deliveryAddress}}</view>
					<view class="info"><text class="name">{{detail.deliveryEmplName}}</text>{{detail.deliveryTel}}</view>
				</view>
			</view>
			<!-- <view class="order-address" v-if="detail.expressageName" @tap="viewLogistics">
				<view class="icon-wrap"><i class="iconfont iconqianshou"></i></view>
				<view class="address-text">
					<view class="address" v-html="getExpressageStatus(detail.expressageStatus)"></view>
					<view class="info">{{detail.expressageName}}</view>
				</view>
				<view class="right-arrow"><i class="iconfont iconxiangyou"></i></view>
			</view> -->
			<view v-if="detail.logisticsOrder" class="order-address" @tap="viewLogistics">
				<view class="icon-wrap"><i class="iconfont iconqianshou"></i></view>
				<view class="address-text">
					<view class="address">查看物流</view>
				</view>
				<view class="right-arrow"><i class="iconfont iconxiangyou"></i></view>
			</view>
			<view v-else class="order-address">
				<view class="icon-wrap"><i class="iconfont iconqianshou"></i></view>
				<view class="address-text">
					<view class="address">待发货</view>
				</view>
			</view>
			
			<view v-else class="order-address">
				<view class="icon-wrap"><i class="iconfont iconqianshou"></i></view>
				<view class="address-text">
					<view class="address">待发货</view>
				</view>
			</view>
		</template>
		<view class="order-section pd1">
			<view class="order-number">
				<view class="number-left">
					<text>{{detail.orderCode}}</text>
				</view>
			</view>
			<view class="tui-goods-item goods-item" v-for="child in detail.orderGoodsDet">
				<!-- 经销商 -->
				<template v-if="jxsFlag==='jxs'">
					<view class="tui-goods-img">
						<image :src="imgSrc + child.imgRelativeUri" />
					</view>
					<view class="tui-goods-info">
						<view class="tui-goods-info-inner">
							<view class="tui-goods-title">{{child.goodsName}} {{child.goodsSapCode}}</view>
							<!-- <view class="tui-goods-sub">创建日期：<text>{{child.createTime}}</text></view> -->
							<view class="tui-price-box">
								<view class="tui-goods-price">{{child.goodsPoints}}<text class="small-size">积分</text></view>
								<view class="tui-goods-num">x{{child.goodsQty}}</view>
							</view>
						</view>
					</view>
				</template>
				<!-- 非经销商 -->
				<template v-else>
					<view class="tui-goods-img">
						<image :src="imgSrc + child.imgRelativeUri" />
					</view>
					<view class="tui-goods-info">
						<view class="tui-goods-info-inner">
							<view class="tui-goods-title">{{child.couponName}}</view>
							<!-- <view class="tui-goods-sub">创建日期：<text></text></view> -->
							<view class="tui-price-box">
								<view class="tui-goods-price">{{child.goodsPoints}}<text class="small-size">积分</text></view>
								<view class="tui-goods-num">x{{child.couponQty}}</view>
							</view>
						</view>
					</view>
				</template>
			</view>
			<view class="points-part">
				<view class="user-item">
					<view class="left">支付方式</view>
					<view class="right">积分</view>
				</view>

				<view class="user-item">
					<view class="left">总计</view>
					<view class="right red">{{detail.orderTotalPoints}}积分</view>
				</view>
				<view class="user-item">
					<view class="left">支付积分</view>
					<view class="right red">{{detail.orderTotalPoints}}积分</view>
				</view>
			</view>
		</view>
		<view class="order-section pd3">
			<uni-steps :options="orderTime" direction="column" :active="stepsActive"></uni-steps>
		</view>
		</template>
		<tui-modal></tui-modal>
	</view>
</template>

<script>
	import uniCopy from '@/utils/uni-copy.js'
	import uniSteps from "@/components/uni-steps/uni-steps.vue"
	import tuiButton from '@/components/button/button';
	export default {
		components: {
			uniSteps,
			tuiButton,
		},
		data() {
			return {
				imgSrc: this.$store.state.imgUrl,
				orderTime: [],
				stepsActive: 0,
				jxsFlag: 'jxs1',
				detail: null,
				from:'',
				id:'',//订单id
			}
		},
		onLoad(options) {
			this.from=options.from;
			this.id=options.id;
			// #ifdef H5
			   this.$wechat.noShare();
			// #endif
			if (this.from === 'agent') {
				this.jxsFlag = 'jxs';
			} else {
				this.jxsFlag = 'notjxs'
				
			}
			this.pointOrderDetail();
		},
		methods: {
			getExpressageStatus(status) {
				return ["已打包", "代发货", "派送中", "已签收"][status - 1]
			},
			viewLogistics() {
				uni.navigateTo({
					url: `/packageD/pages/logisticsInfo/logisticsInfo?orderId=${this.detail.id}`
				})
			},
			pointOrderDetail() {//商品详情
				if(this.jxsFlag =='jxs'){
					this.$http.dealerOrderDetail(this.id).then((res) => {
						if (res.status === 0) {
							this.detail=res.data;
							this.orderTime = [{
								title: '订单创建时间',
								desc: this.detail.createTime
							}]
							if (this.detail.orderDeliveryTime) {
								this.orderTime.push({
									title: '订单签收时间',
									desc: this.detail.orderDeliveryTime
								})
							}
							this.stepsActive = this.orderTime.length - 1;
						}
					})
				}else{
					this.$http.notDealerOrderDetail(this.id).then((res) => {
						if (res.status === 0) {
							this.detail=res.data;
							this.orderTime = [{
								title: '订单创建时间',
								desc: this.detail.payTime
							}]
							if (this.detail.orderDeliveryTime) {
								this.orderTime.push({
									title: '订单签收时间',
									desc: this.detail.orderDeliveryTime
								})
							}
							this.stepsActive = this.orderTime.length - 1;
						}
					})
				}
				
			},
		}
	}
</script>

<style lang="scss">
	@import "@/packageD/static/style/common.scss";
</style>
